package Thread;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
/**阻塞队列的演示*/
public class demo29 {
    public static void main(String[] args) throws InterruptedException {
        BlockingDeque<String> queue1 = new LinkedBlockingDeque<>();
        // put 和 take 方法都是阻塞方法，如果它们在等待时被中断，则会抛出 InterruptedException。
        queue1.put("qqq");
        String elem1 = queue1.take();

        // 阻塞
        BlockingDeque<String> queue2 = new LinkedBlockingDeque<>();
        String elem2 = queue2.take();

        // 阻塞
        BlockingDeque<String> queue3 = new LinkedBlockingDeque<>(100);
        for (int i = 0; i < 100; i++) {
            queue3.put("i");
        }
        queue3.put("e");
        System.out.println(elem2);
    }
}
